package com.dlx.order.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dlx.common.result.Result;
import com.dlx.model.order.ConsumeOrderInfo;
import com.dlx.order.service.ConsumeOrderInfoService;
import com.dlx.vo.order.ConsumeOrderInfoQueryVo;
import com.dlx.vo.order.ConsumeOrderReportQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <h3>smms_parent</h3>
 *
 * @author nglon
 * @description <p>消费控制类</p>
 * @date 2021-11-28 15:58
 **/
@RestController
@RequestMapping("/admin/order/consumeOrder")
public class ConsumeOrderInfoController {

    @Autowired
    private ConsumeOrderInfoService consumeOrderInfoService;

    @PostMapping("{current}/{limit}")
    public Result pageListConsumeOrderInfo(
            @PathVariable Long current,
            @PathVariable Long limit,
            @RequestBody ConsumeOrderInfoQueryVo consumeOrderInfoQueryVo
    ) {
        Page<ConsumeOrderInfo> page = this.consumeOrderInfoService.selectConsumeOrderInfoPage(current, limit, consumeOrderInfoQueryVo);
        return Result.ok(page);
    }

    @PostMapping("update")
    public Result update(@RequestBody ConsumeOrderInfo consumeOrderInfo) {
        boolean flag = this.consumeOrderInfoService.updateById(consumeOrderInfo);
        return flag ? Result.ok().message("修改成功") : Result.fail().message("修改失败");
    }

    @GetMapping("show/{id}")
    public Result show(@PathVariable Long id) {
        ConsumeOrderInfo consumeOrderInfo = this.consumeOrderInfoService.show(id);
        return Result.ok(consumeOrderInfo);
    }

    @DeleteMapping("{id}")
    public Result delete(@PathVariable Long id) {
        boolean flag = this.consumeOrderInfoService.removeById(id);
        return flag ? Result.ok().message("删除成功") : Result.fail().message("删除失败");
    }

    @PostMapping("getMonthlyReport")
    public Map<String, Object> getMonthlyReport(@RequestBody ConsumeOrderReportQueryVo consumeOrderReportQueryVo) {
        return this.consumeOrderInfoService.getMonthlyReport(consumeOrderReportQueryVo);
    }

    @PostMapping("getQuarterlyReport")
    public Map<String, Object> getQuarterlyReport(@RequestBody ConsumeOrderReportQueryVo rechargeOrderReportQueryVo) {
        return this.consumeOrderInfoService.getQuarterlyReport(rechargeOrderReportQueryVo);
    }

    @GetMapping("getAnnualReport")
    public Map<String, Object> getAnnualReport() {
        return this.consumeOrderInfoService.getAnnualReport();
    }
}
